First things first, load in all the packages you’ll need throughout this process.
packages_needed <- c("ggplot2", # graphics
"arm", # display() etc.
"ggfortify")
pk_to_install <- packages_needed [!( packages_needed %in% rownames(installed.packages()) )]
if(length(pk_to_install)>0 ){
install.packages(pk_to_install,repos="http://cran.r-project.org")
}
library(ggplot2)
library(arm)
## Loading required package: MASS
## Loading required package: Matrix
## Loading required package: lme4
##
## arm (Version 1.11-2, built: 2020-7-27)
## Working directory is D:/Documents/Accademics/APSU/AdvancedData_Class/2021_09-14_AdvancedData_GLM_Assignment
library(ggfortify)
Pull in data for both analyses. I am using two of my own datasets, one which contains standardized measurments for Heloderma across their range, and another with records from Vernal Pool monitering across the northeastern part of the US.
Heloderma_Records <- read.csv("data/Heloderma_Records.csv")
Vernal_Pool_Database <- read.csv("data/Mass_Pool_Table.csv")
Start by subsetting all our information down to something we can work with. Gila monsters are notoriously hard to sex based exclusively on external characteristics, although there have been some trends observed. There have been some researchers who have reported that Male gilas tend to have broader heads than females. While this is always discribed as an imperfect means of determining sex, we can test if there is any truth to this pattern.
We subset out only monsters who have been positively sexed as “Male” or “Female” in our database, and then additionally only those monsters who have had “Head Width” measured. Then, we make a new collumn in our data “Bi_Sex” which turns our “Male” and “Female” values into 1 and 0 values so that we can apply a binary distribution to it. I also removed all juviniles and sub adults based off size thresholds set by Beck (2005) as a means of simplifying the dataset (this method is said to work much better on Adults)
Gila_Data <- Heloderma_Records[Heloderma_Records$Species == "suspectum",]
Gila_Data <- Gila_Data[is.na(Gila_Data$HW) == FALSE,]
Gila_Data <- subset(Gila_Data, Sex == "M" | Sex == "F")
Gila_Data <- Gila_Data[Gila_Data$HW != 0,]
Gila_Data <- Gila_Data[Gila_Data$SVL > 220,]
for(i in 1:dim(Gila_Data)[1]){
Gila_Data$Bi_Sex[i] <- ifelse(Gila_Data$Sex[i] == "F", 0, 1)}